package com.whnk.model.service.impl;

import java.util.List;
import java.util.UUID;

import com.whnk.common.core.utils.DateUtils;
import com.whnk.common.core.utils.IdUtils;
import com.whnk.common.security.service.TokenService;
import com.whnk.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.whnk.model.mapper.InterServicesMapper;
import com.whnk.model.domain.InterServices;
import com.whnk.model.service.IInterServicesService;

/**
 * 接口服务Service业务层处理
 *
 * @author whnk
 * @date 2021-11-19
 */
@Service
public class InterServicesServiceImpl implements IInterServicesService
{
    @Autowired
    private InterServicesMapper interServicesMapper;

    @Autowired
    private TokenService tokenService;

    /**
     * 查询接口服务
     *
     * @param tableId 接口服务主键
     * @return 接口服务
     */
    @Override
    public InterServices selectInterServicesByTableId(String tableId)
    {
        return interServicesMapper.selectInterServicesByTableId(tableId);
    }

    /**
     * 查询接口服务列表
     *
     * @param interServices 接口服务
     * @return 接口服务
     */
    @Override
    public List<InterServices> selectInterServicesList(InterServices interServices)
    {
        return interServicesMapper.selectInterServicesList(interServices);
    }

    /**
     * 新增接口服务
     *
     * @param interServices 接口服务
     * @return 结果
     */
    @Override
    public int insertInterServices(InterServices interServices)
    {
        // 获取当前的用户
        LoginUser loginUser = tokenService.getLoginUser();
        interServices.setTableId(IdUtils.simpleUUID());
        interServices.setCreateBy(loginUser.getUsername());
        interServices.setCreateTime(DateUtils.getNowDate());
        return interServicesMapper.insertInterServices(interServices);
    }

    /**
     * 修改接口服务
     *
     * @param interServices 接口服务
     * @return 结果
     */
    @Override
    public int updateInterServices(InterServices interServices)
    {
        LoginUser loginUser = tokenService.getLoginUser();
        interServices.setUpdateBy(loginUser.getUsername());
        interServices.setUpdateTime(DateUtils.getNowDate());
        return interServicesMapper.updateInterServices(interServices);
    }

    /**
     * 批量删除接口服务
     *
     * @param tableIds 需要删除的接口服务主键
     * @return 结果
     */
    @Override
    public int deleteInterServicesByTableIds(String[] tableIds)
    {
        return interServicesMapper.deleteInterServicesByTableIds(tableIds);
    }

    /**
     * 删除接口服务信息
     *
     * @param tableId 接口服务主键
     * @return 结果
     */
    @Override
    public int deleteInterServicesByTableId(String tableId)
    {
        return interServicesMapper.deleteInterServicesByTableId(tableId);
    }
}
